<?php
/**
 * Defines the Photo page type
 */
 
class PhotoPage extends SecurePage {
   
}
 
class PhotoPage_Controller extends SecurePage_Controller {

	function PhotoForm() {
		// Create fieldset containing fields
		$fields = new FieldSet(
			new FileField('Photo'),
			new DateField('Date', 'Date'),
			new TextField('Photographer')
		);

		// Create action for form submission
		$actions = new FieldSet(new FormAction('submitPhoto', 'Submit'));
	  
		// Set required fields
		$validator = new RequiredFields('Photo', 'Date', 'Photographer');
 
		return new Form($this, 'PhotoForm', $fields, $actions, $validator);
	}

	function submitPhoto($data, $form) {
		// Save form data into new Photo object and write to database	
		$submission = new Photo();
		$form->saveInto($submission);
		$submission->write();
 
		Director::redirectBack();
	}

}
?>